package com.sike.netty.im.client.handler;

import com.sike.netty.im.client.ClientConnectRunner;
import com.sike.netty.im.common.codc.CommandBodyDecoder;
import com.sike.netty.im.common.codc.MessageCodec;
import com.sike.netty.im.common.codc.ProtocolFrameDecoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;

public class ClientInitializer extends ChannelInitializer<SocketChannel> {

    private ClientConnectRunner clientConnectRunner;

    public ClientInitializer(ClientConnectRunner clientConnectRunner) {
        this.clientConnectRunner = clientConnectRunner;
    }

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline().addLast(new ReconnectHandler(this.clientConnectRunner));
        ch.pipeline().addLast(new ImIdleStateHandler());
        ch.pipeline().addLast(new ProtocolFrameDecoder());
        ch.pipeline().addLast(new MessageCodec());
        ch.pipeline().addLast(new CommandBodyDecoder());
        ch.pipeline().addLast(new HearBeatTimerHandler());
        ch.pipeline().addLast(new LoginHandler());
        ch.pipeline().addLast(new LoginResponseHandler());
        ch.pipeline().addLast(new MainMenuHandler());
        ch.pipeline().addLast(new OneChatHandler());
        ch.pipeline().addLast(new OneChatResponseHandler());
        ch.pipeline().addLast(new CreateGroupRequestHandler());
        ch.pipeline().addLast(new CreateGroupResponseHandler());
        ch.pipeline().addLast(new JoinGroupRequestHandler());
        ch.pipeline().addLast(new JoinGroupResponseHandler());
        ch.pipeline().addLast(new ListGroupMembersRequestHandler());
        ch.pipeline().addLast(new ListGroupMembersResponseHandler());
        ch.pipeline().addLast(new ExitGroupRequestHandler());
        ch.pipeline().addLast(new ExitGroupResponseHandler());
        ch.pipeline().addLast(new GroupChatRequestHandler());
        ch.pipeline().addLast(new GroupChatResponseHandler());
    }
}
